<?php
	require_once('paths.inc');
    require_once('security.inc');

    require_once('page.inc');    
    require_once('utils.inc');
    require_once(DB_PATH.'db.inc');    
    include (INCLUDE_PATH.'constants.inc');
    
	session_start();
    checkIsLoggedIn();
	
	function curata($var) {
		return !($var == "");
	}
	
	$db = db_connect();
	$indecsi = $_GET['indecsi'];
	$index_arr = explode(";", $indecsi);
	
	select_language();
		
	$index_arr = array_filter($index_arr, "curata");
	$id_client = $_SESSION['user_logat']->id_client;

    try {
        $user_admin = User::queryLoad($db, $_SESSION['client_logat']->admin_user_id);
    }
    catch (QueryLoadUserException $e) {
        redirectOnError(CT_PRINT_CONTRACT_FAIL);
    }
	
    header("Pragma: public"); // required                                                                                                                        
    header("Expires: 0");                                                                                                                                    
	header("Content-Description: File Transfer");                                                                                                        
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");                                                                             
	header("Content-type: application/pdf");                                                                                                                 
	header('Content-Transfer-Encoding: binary');                       
	$cale_fisier = USERS_PATH . $_SESSION['user_logat']->id_user . "/contract_" . $id_client . ".pdf";                                                                                      
	header("Content-Disposition: attachment; filename=\"" . basename($cale_fisier) . '"');                  
    
    print_contractWithOO($_SESSION['client_logat'], $user_admin);
    ob_clean();
    flush();
	readfile($cale_fisier);  
	exit;   	
?>

